package edu.whut.method;
/*
* 数组元素交换
* */
public class test03 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        swapArr2(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
    private static void swapArr1(int[] arr) {
        int temp;
        for (int i = 0; i < arr.length/2; i++) {
            temp = arr[i];
            arr[i] = arr[arr.length-1-i];
            arr[arr.length-1-i] = temp;
        }
    }
    private static void swapArr2(int[] arr){
        int i=0;
        int j=arr.length-1;
        int temp;
        while (i<j){
            temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
            i++;
            j--;
        }
    }
}
